import axios, { AxiosInstance } from "axios";
import {
  type Config,
  CrawlerFileUtils,
  getRandomIP,
  getRandomUserAgent,
} from "../../utils/baseUtils.js";

// 51miz 爬虫配置文件类型
type Config51miz = Config & {
  types: ("tupian" | "beijing" | "chahua")[]; // 爬取类型，图片、背景、插画 可选数组
};
const fileUtils = new CrawlerFileUtils<Config51miz>(import.meta.url);

// =================== 创建一个 axios 实例 ===================
const axiosInstance: AxiosInstance = axios.create({
  timeout: 10000, // 10秒超时
});
// 随机化的处理
axiosInstance.interceptors.request.use((config) => {
  config.headers["User-Agent"] = getRandomUserAgent();
  config.headers["X-Forwarded-For"] = getRandomIP();
  config.headers["X-Real-IP"] = getRandomIP();
  config.headers["Referer"] = "https://www.51miz.com/";
  return config;
});

export { axiosInstance, fileUtils };
